﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SysSU.JSONRPC
{
    class JSONRPC2ParamsType
    {
        public static readonly int NO_PARAMS_CONST = 0;
        public static readonly JSONRPC2ParamsType NO_PARAMS = new JSONRPC2ParamsType("NO_PARAMS", NO_PARAMS_CONST);

        public static readonly int ARRAY_CONST = 1;
        public static readonly JSONRPC2ParamsType ARRAY = new JSONRPC2ParamsType("ARRAY", ARRAY_CONST);

        public static readonly int OBJECT_CONST = 2;
        public static readonly JSONRPC2ParamsType OBJECT = new JSONRPC2ParamsType("OBJECT", OBJECT_CONST);

        public string Name { get; private set; }
        public int IntValue { get; private set; }

        private JSONRPC2ParamsType(string name, int intValue)
        {
            this.Name = name;
            this.IntValue = intValue;
        }

        public static JSONRPC2ParamsType ValueOf(int intValue)
        {
            switch (intValue)
            {
                case 0:
                    return NO_PARAMS;
                case 1:
                    return ARRAY;
                case 2:
                    return OBJECT;
                default:
                    return null;
            }
        }

        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return false;
            }
            else if (obj == this)
            {
                return true;
            }
            else if (obj is JSONRPC2ParamsType)
            {
                return (IntValue == (obj as JSONRPC2ParamsType).IntValue);
            }
            else
            {
                return false;
            }
        }

        public override string ToString()
        {
            return Name;
        }
    }
}
